package com.unicampmaps;

import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class VenueCursorAdapter extends SimpleCursorAdapter {
	private Context mContext;
	private int mLayout;

	public VenueCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
	    super(context, layout, c, from, to, flags);
	    // TODO Auto-generated constructor stub
	    mContext = context;
	    mLayout = layout;
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
	    LayoutInflater inflater = LayoutInflater.from(context);
	    View view;
	    int id = cursor.getInt(cursor.getColumnIndex(VenueData.C_ID));
	    
	    //int hasImage = cursor.getInt(cursor.getColumnIndex(VenueData.C_IMAGE));
        view = inflater.inflate(R.layout.autocomplete_item, parent, false);
	    
	    return view;
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
	    int id = cursor.getInt(cursor.getColumnIndex(VenueData.C_ID));
	    String hasImage = cursor.getString(cursor.getColumnIndex(VenueData.C_IMAGE));
	    
	    String name = cursor.getString(cursor.getColumnIndex(VenueData.C_NAME));
	    String abbr = cursor.getString(cursor.getColumnIndex(VenueData.C_ABBR));
	    
	    TextView topTextView = (TextView) view.findViewById(R.id.label_top);
	    TextView bottomTextView = (TextView) view.findViewById(R.id.label_bottom);

	    topTextView.setText(name);
	    bottomTextView.setText(abbr);
	    
	    /*if (!hasImage.trim().equals("")) {
	        imageView.setVisibility(ImageView.GONE);
	    } else {
	        String bitmapPath = Environment.getExternalStorageDirectory().getPath() + "/feed/" + id + "_thumb.jpg";
	        Bitmap bitmap = BitmapFactory.decodeFile(bitmapPath);
	        BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap);
	        imageView.setImageDrawable(bitmapDrawable);
	        imageView.setVisibility(ImageView.VISIBLE);
	    }*/
	}
}
